//
//  SortMoreCollectionViewCell.m
//  MountEverestFM
//
//  Created by dllo on 15/11/2.
//  Copyright © 2015年 chenn. All rights reserved.
//

#import "SortMoreCollectionViewCell.h"
#import "SortMoreTableViewCell.h"
#import "SortMoreXiangTableViewCell.h"
#import "SortDetailedTVC.h"

@implementation SortMoreCollectionViewCell

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.tableView=[[UITableView alloc]init];
        self.tableView.delegate=self;
        self.tableView.dataSource=self;
        [self.contentView addSubview:self.tableView];
       
        
        MJRefreshNormalHeader *header=[MJRefreshNormalHeader headerWithRefreshingBlock:^{

            self.blockMj1();

            [self.tableView.header endRefreshing];
        }];
        
        self.tableView.header=header;

        
        
    }
    return self;

}
-(void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    self.tableView.frame=self.contentView.bounds;
    
}
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section==0) {
        return 1;
    }
    return self.arr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        SortMoreTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"sange"];
        if (!cell) {
            cell=[[SortMoreTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"sange"];
            
        }
        [cell.button1 setTitle:@"最火" forState:UIControlStateNormal];
        [cell.button1 addTarget:self action:@selector(button1:) forControlEvents:UIControlEventTouchUpInside];
        [cell.button1 setTintColor:[UIColor redColor]];
      
        
        [cell.button2 setTitle:@"最近更新" forState:UIControlStateNormal];
        [cell.button2 addTarget:self action:@selector(button2:) forControlEvents:UIControlEventTouchUpInside];
        

        [cell.button3 setTitle:@"经典" forState:UIControlStateNormal];
        [cell.button3 addTarget:self action:@selector(button3:) forControlEvents:UIControlEventTouchUpInside];
        

        
        return cell;
    }else{
        SortDetailedTVC *cell=[tableView dequeueReusableCellWithIdentifier:@"xiangxiang"];
        if (!cell) {
            cell=[[SortDetailedTVC alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"xiangxiang"];
        }
        [cell.imageV1 sd_setImageWithURL:[NSURL URLWithString:[[self.arr objectAtIndex:indexPath.row] objectForKey:@"albumCoverUrl290"]] placeholderImage:[UIImage imageNamed:@"find_kind_btn_default@3x.png"]];
      
        cell.lable1.text=[[self.arr objectAtIndex:indexPath.row] objectForKey:@"title"];
        cell.lable2.text=[[self.arr objectAtIndex:indexPath.row] objectForKey:@"intro"];
      CGFloat f=[[[self.arr objectAtIndex:indexPath.row] objectForKey:@"playsCounts"] floatValue];
        
        
        cell.lable4.text=[[[self.arr objectAtIndex:indexPath.row] objectForKey:@"tracksCounts"] stringValue];

        cell.imageV2.image=[UIImage imageNamed:@"sound_playtimes@3x"];
        cell.imageV3.image=[UIImage imageNamed:@"album_tracks@3x.png"];
        
        cell.imV.image=[UIImage imageNamed:@"cell_arrow_all.png"];
        
        if (f<10000) {
            cell.lable3.text=[NSString stringWithFormat:@"%.0f",f];
        }else{
            cell.lable3.text=[NSString stringWithFormat:@"%.2f万",f/10000];
        }

      
        return cell;
    }
    
    
    return NULL;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        return FM_Screen_Pts_Height*75;
    }
    return FM_Screen_Pts_Width*70+FM_Screen_Pts_Height*40;
}
-(void)button1:(UIButton *)bu
{
    
            self.block1();
    
    
}
-(void)button2:(UIButton *)bu
{
  
    
    
    
    self.block2();
    
    
}
-(void)button3:(UIButton *)bu
{
    
    self.block3();
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    self.blockdian([self.arr objectAtIndex:indexPath.row]);
    
}





@end
